package com.hfy.kandian.controller;


import com.hfy.kandian.dao.command.UserLoginByPhoneNumberCommand;
import com.hfy.kandian.dao.command.UserInfoCommand;
import com.hfy.kandian.dao.representation.UserRepresentation;
import com.hfy.kandian.entity.Book;
import com.hfy.kandian.service.UserService;
import javax.validation.constraints.NotNull;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author HAN XIAOYANG
 * @since 2020-12-30
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @ApiOperation(value = "通过手机号登录")
    @PostMapping("/loginByPhoneNum")
    public int loginByPhoneNum (@RequestBody UserLoginByPhoneNumberCommand userLoginByPhoneNumberCommand){
        return  userService.loginByPhoneNum(userLoginByPhoneNumberCommand.getUserPhone(),userLoginByPhoneNumberCommand.getUserPassword());
    }


    @ApiOperation(value = "注册")
    @PostMapping("/register")
    public int register(@RequestBody UserInfoCommand userInfoCommand){
        return userService.register(userInfoCommand);
    }


    @ApiOperation(value = "更改用户信息")
    @PostMapping("/modify")
    public int modify(@RequestBody UserInfoCommand userInfoCommand){
        return userService.modify(userInfoCommand);
    }


    @ApiOperation(value = "展示用户信息(依据Id搜索用户)")
    @GetMapping("/show/{userId}")
    public UserRepresentation show(@PathVariable int userId){
        return userService.findById(userId);
    }

    @ApiOperation(value = "手机验证码登录")
    @GetMapping("/loginBySMSCode/{phoneNum}")
    public int loingBySMSCode(@PathVariable String phoneNum){
        return userService.loginBySMSCode(phoneNum);
    }

    @ApiOperation(value = "测试")
    @GetMapping("/test/{value}")
    public int test(@NotNull(message = "不可为空的测试的提示信息") @PathVariable BigDecimal value){
        return 1;
    }


}

